"""author: wenyao
   data: 2021/11/4
   project: cjh
"""
#列表  -- 链表 和 数组
#有序项目集合
#可以存放任何数据类型对象
#可变数据类型

###########列表的定义
# [root@sdyxz ~]# python3
# Python 3.6.8 (default, Aug 24 2020, 17:57:11)
# [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
# Type "help", "copyright", "credits" or "license" for more information.
# >>> lst = []
# >>> type(lst)
# <class 'list'>
# >>> lst2 = list()
# >>> type(lst2)
# <class 'list'>
# >>> lst
# []
# >>> lst2
# []
# >>> lst3 = [1,2,3]
# >>> lst3
# [1, 2, 3]
# >>> lst2 = list('abc')
# >>> lst2
# ['a', 'b', 'c']
# >>> lst2 = list(123)   ---  要放入一个可迭代对象（可以被for循环获取的）
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'int' object is not iterable
# >>> lst2 = list(range(5))
# >>> lst2
# [0, 1, 2, 3, 4]

#有序的项目集合
# >>> lst2[3]
# 3
# >>> lst2[2:3]
# [2]
# >>> lst2[2:4]
# [2, 3]

#存放任何数据类型对象
# >>> lst3 = [print, None, 1, 'abc',True]
# >>> lst3
# [<built-in function print>, None, 1, 'abc', True]
# >>> lst3[0]
# <built-in function print>
# >>> lst3[0]("this is test")
# this is test
# >>> print("this is test")
# this is test
# >>> lst3 = [print(), None, 1, 'abc',True]

# >>> lst3
# [None, None, 1, 'abc', True]


#可变数据类型  vs 不可变数据类型
#在原地址内存空间里，能修改内容的就是可变数据类型，不能修改内容的就是不可变数据类型
# >>> id(lst3)
# 139735912779400
# >>> lst3.append(3)
# >>> id(lst3)
# 139735912779400
# >>> str1="abc"
# >>> str1[1]
# 'b'
# >>> str1[1] = "d"
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'str' object does not support item assignment
# >>> lst3
# [None, None, 1, 'abc', True, 2, 3]
# >>> lst3[1] = "xxxyyy"
# >>> lst3
# [None, 'xxxyyy', 1, 'abc', True, 2, 3]

#列表的索引以及切片
#和str类型一样
#[start:end:step]
# >>> lst3[2:5]
# [1, 'abc', True]
# >>> lst3[2:5:-1]
# []
# >>> lst3
# [None, 'xxxyyy', 1, 'abc', True, 2, 3]
# >>> lst3[-2:2:-2]
# [2, 'abc']
# >>> lst3[:-2]
# [None, 'xxxyyy', 1, 'abc', True]
# >>>

#slice对象
# >>> lst1 = ["aa","bb",1,3,5,6]
# >>> lst2 =["xx","yy","zz","dd"]
# >>> lst1[:2]
# ['aa', 'bb']
# >>> lst1[:3]
# ['aa', 'bb', 1]
# >>> lst2[:3]
# ['xx', 'yy', 'zz']
# >>> s1 = slice(0,3,1)
# >>> lst2[s1]
# ['xx', 'yy', 'zz']
# >>> lst1[s1]
# ['aa', 'bb', 1]
# >>> str1 = "abcdefg"
# >>> str1[s1]
# 'abc'

#增  -- append  insert  extend
# >>> lst3.append(4)
# >>> lst3
# [None, 'xxxyyy', 1, 'abc', True, 2, 3, 4]
# >>> lst3.append(["a","b"])
# >>> lst3
# [None, 'xxxyyy', 1, 'abc', True, 2, 3, 4, ['a', 'b']]
# >>> lst3[8]
# ['a', 'b']
# >>> lst3[8][1]
# 'b'
# >>> lst3[8]
# ['a', 'b']
# >>> lst3
# [None, 'xxxyyy', 1, 'abc', True, 2, 3, 4, ['a', 'b']]
# >>> lst3.insert(2,"tt")
# >>> lst3
# [None, 'xxxyyy', 'tt', 1, 'abc', True, 2, 3, 4, ['a', 'b']]
# >>> lst3.insert(20,"tt")
# >>> lst3
# [None, 'xxxyyy', 'tt', 1, 'abc', True, 2, 3, 4, ['a', 'b'], 'tt']
# >>> lst3.extend("xyz")
# >>> lst3
# [None, 'xxxyyy', 'tt', 1, 'abc', True, 2, 3, 4, ['a', 'b'], 'tt', 'x', 'y', 'z']
# >>> lst3.extend(12)   ---  要传入一个可迭代对象  （可以被for循环获取）
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: 'int' object is not iterable
# >>>

###########
# >>> lst
# ['a', 'b', 'c']
# >>> lst + lst1
# ['a', 'b', 'c', 'aa', 'bb', 1, 3, 5, 6]
# >>> result = lst + lst1
# >>>

#删除 pop  -- 指定下标删除，默认删除最后一个元素，并且将删除的元素作为返回值返回
# >>> lst1
# ['aa', 'bb', 1, 3, 5, 6]
# >>> lst1.pop()
# 6
# >>> lst1.pop()
# 5
# >>> lst1
# ['aa', 'bb', 1, 3]
# >>> result = lst1.pop()
# >>> print(result)
# 3
# >>> lst1
# ['aa', 'bb', 1]
# >>> result = lst1.pop(1)
# >>> print(result)
# bb
# >>> lst1
# ['aa', 1]
# >>> help(pop)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'pop' is not defined
# >>> help(lst1.pop)

#有一条船，船上有40个人。船超载，20个人。
#每数到第九个就让他下船，最后输出哪些人下船了
# out = list(range(1, 41))
# stay = 20
# while len(out) > stay:
#     print("编号为{}的人下船了".format(out.pop(8)))
#     out += out[0:8]
#     out = out[-1:7:-1]
#     out = out[::-1]
# print("剩下的人的编号为:", out)

# lst = list(range(1,41))
# while len(lst) > 20:
#     i = lst[8]
#     lst = lst[9:] + lst[:8]
#     print(f"编号为{i}的人下船了")
#
# member = list(range(1, 41))
# while len(member) > 20:
#     i = 1
#     while i < 9:
#         # 从第一个开始 将不是第9个的人放到末尾
#         member.append(member.pop(0))
#         # print( member)
#         i = i + 1
#     # 是第九个人 就下船
#     print(member.pop(0), "下船")
#
# list1=[]
# for i in range(40):
#     list1.append(i+1)
# sums=40
# j=0
# while sums>20:
#          j+=8
#          if j>sums-1:
#              d=j%len(list1)
#              j = d
#              print(list1.pop(d),end=" ")
#          else:
#              print(list1.pop(j),end=" ")
#          sums-=1

#删除 - del  remove  clear
# >>> lst
# ['a', 'b', 'c', 'a', 'c', '1']
# >>> lst.remove('a')
# >>> lst
# ['b', 'c', 'a', 'c', '1']
# >>> lst.remove('d')
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: list.remove(x): x not in list
# >>> lst
# ['b', 'c', 'a', 'c', '1']
# >>> lst[2:4]
# ['a', 'c']
# >>> del lst[2:4]
# >>> lst
# ['b', 'c', '1']
# >>> a = 10
# >>> del a
# >>> a
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# NameError: name 'a' is not defined
# >>> lst.clear()
# >>> lst
# []
# >>>

#修改 -- 下标 切片修改
#切片修改  -- 赋值一个可迭代对象
#如果查找出来的列表不为空，则替换查找出来的内容
#如果查找出来的列表的start和end一致， 那就在start的位置添加响应的值
# >>> lst = ['x','y','z','a','b','c']
# >>> lst[0]
# 'x'
# >>> lst[0]='p'
# >>> lst
# ['p', 'y', 'z', 'a', 'b', 'c']
# >>> lst[2:5]
# ['z', 'a', 'b']
# >>> lst[2:5] = 'a'
# >>> lst
# ['p', 'y', 'a', 'c']
# >>> lst = ['x','y','z','a','b','c']
# >>> lst[2:5] = 12
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: can only assign an iterable
# >>> lst[2:5] = 'bcd'
# >>> lst
# ['x', 'y', 'b', 'c', 'd', 'c']
# >>> lst[2:5:-1]
# []
# >>> lst[2:5:-1] = "eeeee"
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: attempt to assign sequence of size 5 to extended slice of size 0
# >>> lst[2:5:-1] = "e"
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: attempt to assign sequence of size 1 to extended slice of size 0
# >>> #lst[2:2]
# ...
# >>> lst
# ['x', 'y', 'b', 'c', 'd', 'c']
# >>> lst[2:2]
# []
# >>> lst[2:2] = "rrrr"
# >>> lst
# ['x', 'y', 'r', 'r', 'r', 'r', 'b', 'c', 'd', 'c']
# >>> lst[2:2] = ["rrrr"]
# >>> lst
# ['x', 'y', 'rrrr', 'r', 'r', 'r', 'r', 'b', 'c', 'd', 'c']

#reverse()   进行列表反转
#sort()      进行排序
# >>> lst
# [10, 'y', 'rrrr', 'r', 'r', 'r', 'r', 'b', 'c', 'd', 'c']
# >>> dir(lst)
# ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
# >>> lst.reverse()
# >>> lst
# ['c', 'd', 'c', 'b', 'r', 'r', 'r', 'r', 'rrrr', 'y', 10]
# >>> lst.sort()
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: '<' not supported between instances of 'int' and 'str'
# >>> lst = [3,6,2,7]
# >>> lst.sort()
# >>> lst
# [2, 3, 6, 7]
# >>> lst.sort(reverse = True)
# >>> lst
# [7, 6, 3, 2]

# >>> lst
# [7, 6, 3, 2]
# >>> lst[::-1]
# [2, 3, 6, 7]
# >>> lst
# [7, 6, 3, 2]
# >>> lst.reverse()
# >>> lst
# [2, 3, 6, 7]

######复制拷贝
# >>> lst1 = ["a","b","c"]
# >>>
# >>> lst2 = lst1
# >>> lst2
# ['a', 'b', 'c']
# >>> lst1
# ['a', 'b', 'c']
# >>> lst2[1]="x"
# >>> lst1
# ['a', 'x', 'c']
# >>> lst2
# ['a', 'x', 'c']
# >>> lst2 = lst1[::]
# >>> lst1[::]
# ['a', 'x', 'c']
# >>> lst2 = lst1[::]
# >>>
# >>> lst2 = lst1.copy()
# >>> lst2
# ['a', 'x', 'c']
# >>> id(lst1)
# 139735892922440
# >>> id(lst2)
# 139735892830280
# >>> lst2[0] = 4
# >>> lst2
# [4, 'x', 'c']
# >>> lst1
# ['a', 'x', 'c']

#查找统计类
# >>> len(lst)
# 4
# >>> lst.count("2")
# 0
# >>> lst.count(2)
# 1
# >>> lst.index(3)
# 1
# >>> lst.index(9)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# ValueError: 9 is not in list

##############遍历
# lst1 = ["ab","cd","e","f"]
# for i in lst1:
#     print(i)
#
# for i in enumerate(lst1):
#     print(i)
#
# for i,j in enumerate(lst1):
#     print(f"{i} --> {j}")

#成员关系运算符
# if "ab" in lst1:
#     print("ok")

###
# lst = [2,5,6,7,3,1,4]
# 从键盘接受用户输入，输入一个整数 10
# 返回两个数相加等于10这个数的下标  2，6

num = int(input("请输入一个整数："))
lst = [2, 3, 7, 67, 6, 4, 89, 9, 0, 1,7,3, 8, 5,12]
# i = 0
# for i in range(len(lst)):
#     for j in range(i + 1, len(lst)):
#         if lst[i] + lst[j] == num:
#             print(f"{lst[i]}与{lst[j]}的和为{num}，下标分别为{i},{j}, ")

# for  i,j in enumerate(lst):
#     num1 = num - j
#     if num1 in lst[i+1:] and lst.index(num1) > i:
#         print(f"两数之和等于{num}的下标为{i},{lst.index(num1)}")



